﻿using System;
using System.Collections.Generic;
using System.Text;
using CoderJoe.WoW.GearManager.Views;
using System.Drawing;
using System.Windows.Forms;
using CoderJoe.WoW.Services;

namespace CoderJoe.WoW.GearManager
{
    public class EquipmentButtonController
        : Controller
    {
        public EquipmentButtonController(Workspace workspace)
            : base(workspace)
        {

        }

        public void RegisterButton(EquipmentButton button)
        {
            button.MouseHover += new EventHandler(Button_MouseHover);
            button.Click += new EventHandler(Button_Click);
            button.MouseClick += new System.Windows.Forms.MouseEventHandler(Button_MouseClick);
        }

        void Button_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                EquipmentButton button = (EquipmentButton)sender;
                ContextMenuStrip menuStrip = CreateContextMenu(button);
                menuStrip.Show(button, new Point(e.X, e.Y));
            }
        }

        private ContextMenuStrip CreateContextMenu(EquipmentButton button)
        {
            return new ContextMenuStrip();
        }

        void Button_Click(object sender, EventArgs e)
        {
            EquipmentButton button = (EquipmentButton)sender;
            ItemService itemService = Workspace.Resolve<ItemService>();
            Item item = itemService.FindOrLoadItem(button.Model.ItemId);
            MessageBox.Show(item.Name);
        }

        void Button_MouseHover(object sender, EventArgs e)
        {
            EquipmentButton button = (EquipmentButton)sender;
            ItemToolTipController toolTipController = Workspace.Resolve<ItemToolTipController>();
            toolTipController.Show(button.Model.ItemId, button, button.Parent.PointToScreen(new Point(button.Right, button.Top)));
        }
    }
}
